/**
 * @param {number[][]} matrix
 * @return {number}
 */
 var maxMatrixSum = function(matrix) {
  const arr = matrix.flat()
  let cnt = 0
  let min = Number.MAX_SAFE_INTEGER
  for(let i = 0; i<arr.length; i++){
    if(arr[i] < 0){
      cnt++
    }
    min = Math.min(min, Math.abs(arr[i]))
  }
  const sum = arr.reduce((pre,cur) => Math.abs(pre)+Math.abs(cur),0)
  return (cnt % 2 === 0) ? sum : sum-2*min
};